﻿import Taro, { Component } from '@tarojs/taro'
import { Swiper, SwiperItem, Image, View, Text } from '@tarojs/components'
import '../../assets/common.scss'
import CommonJs from '../../utils/common'
import './index.scss'

export default class changegw extends Component {
  constructor(props) {
    super(props)
    this.state = {
      gwinfo:'',
      isload:1,
      reason:"",
      reasonindex:0,
      qid:"",
      baseurl:CommonJs.geturl()
    }
  }
  config = {
    navigationBarTitleText:'更换顾问'
  }
  
  componentWillMount () {
  	  var par=this.$router.params;
  	  var cid=par.cid;
  	  if(cid){
	      this.getreason()
	      this.getgwinfo(cid)
	      this.setState({
		    	 qid:par.qid
		    })
	    }
  }
  componentDidShow () {
  }
  getgwinfo(cid){
  	var url="/crmweb/papi/v1.9/customer-shop/crate/customerShop?consultantId="+cid
  	var _this=this
  	CommonJs.ajaxRequest(url,'','POST',function(res){
		_this.setState({
	      gwinfo:res.data
	    })
  	},"wfw")
  }
  getreason(){
  	var url="/crm/iapi/v1.9/change-reason"
  	var _this=this
  	CommonJs.ajaxRequest(url,'','GET',function(res){
		_this.setState({
	      reason:res.data
	    })
  	},"wfw")
  }
  choosely(index){
  	this.setState({
	    reasonindex:index
	  })
  }
  sure(){
  	var url="/crmweb/papi/v1.9/customer-shop"
  	var _this=this
  	var dates={
  		"nowConsultant": {
		  	"id":this.state.gwinfo.newConsultant.id
		  },
		  "changeReason": {
		    "id": this.state.reason[this.state.reasonindex].id
		  },
		  "oldConsultant": {
		    "id":this.state.gwinfo.oldConsultant.id
		  }
  	}
  	CommonJs.ajaxRequest(url,dates,'POST',function(res){
  		
				Taro.showToast({
	        title:'更换成功，界面跳转中..',
	        icon: 'none',
	        duration: 2000
	     });
      setTimeout(function(){
      	//console.log(_this.state.qid+"//DDD")
      	CommonJs.open('/pages/xijia/grouplist');
      },2000)
  	},"wfw")
  }
  nochange(){
  	//CommonJs.open('/pages/activity/activity?scene='+this.state.qid);
  	CommonJs.open('/pages/xijia/grouplist');
  }
  render () {
    const reason = this.state.reason
    const gwinfo = this.state.gwinfo
    return (
      <View className='page' style={this.state.isload==1?'display:block':'display:none'}>
      	<View className='change-page'>
	        <View className='change-tips'>
	        	<View className='change-tips01'>-----同一个群只有一个顾问,是否替换-----</View>
	        	<View className='change-tips02'>换<Text className='change-tips03'>{gwinfo.newConsultant.name}</Text>为您的专属顾问?</View>
	        </View>
	        <View className='change-user'>
	        	<View className='change-dl'>
	        		<View className='change-dt'><Image className='change-tx' mode='scaleToFill' src={gwinfo.oldConsultant.headPortrait!=null?gwinfo.oldConsultant.headPortrait:this.baseurl+'/kedouimg/A6984900727459logo.png'}></Image></View>
	        		<View className='change-dd'>{gwinfo.oldConsultant.name}</View>
	        		<View className='change-du'>{gwinfo.oldConsultant.shopName}</View>
	        	</View>
	        	<View className='change-dlts'>
	        		<Image className='change-jt' mode='scaleToFill' src='https://minichat.g2ma.com/kedouimg/goselect.png'></Image>
	        	</View>
	        	<View className='change-dl'>
	        		<View className='change-dt'><Image className='change-tx' mode='scaleToFill' src={gwinfo.newConsultant.headPortrait!=null?gwinfo.newConsultant.headPortrait:this.baseurl+'/kedouimg/A6984900727459logo.png'}></Image></View>
	        		<View className='change-dd'>{gwinfo.newConsultant.name}</View>
	        		<View className='change-du'>{gwinfo.newConsultant.shopName}</View>
	        	</View>
	        </View>
	        <View className='change-ly'>
	        	<View className='change-tit'>请选择更换顾问的理由</View>
	        	{reason.map((item, index) => (
	        	<View className='change-ly-li' onClick={this.choosely.bind(this,index)} >
	        		<Image className='change-quan' mode='scaleToFill' src={reasonindex==index?'https://minichat.g2ma.com/kedouimg/icon24.png':'https://minichat.g2ma.com/kedouimg/icon23.png'}></Image>
	        		<Text className='change-test'>{item.name}</Text>
	        	</View>
	        	))}
	        	
	        </View>
	        <View className='change-btn change-btn01' onClick={this.nochange.bind(this)} >取消更换</View>
	        <View className='change-btn' onClick={this.sure.bind(this)} >确定更换</View>
	      </View>
	    </View>
    )
  }
}